'use strict';

const Controller = require('egg').Controller;

class baseController extends Controller {
	/**
	 * 200 ~ 299
	 * 
	 * 200 统一成功返回
	 * 
	 */
	//统一成功返回
	success(data) {
		this.ctx.body = {
			code:200,
			data:data,
		};
	}
	
	/**
	 * 300 ~ 399
	 * 
	 * 300 请登录
	 */
	//统一需要登陆返回
	needLogin(msg = '请登陆') {
		this.ctx.body = {
			code:300,
			msg:msg,
		};
	}

	/**
	 * 400 ~ 499
	 * 
	 * 401 通用数据错误返回
	 */
	fail(msg = "参数错误") {
		// console.log('msg',msg);
		this.ctx.body = {
			code:401,
			msg:msg,
		};
	}

	/**
	 * 验证当前用户是否是正常登陆状态
	 */
	async checkLogin(key){
		const ctx = this.ctx;
		let user = await ctx.service.members.findOne({key:key});
		return user;
	}

}

module.exports = baseController;